<?php
/**
 * @copyright pateo
 * @author sunpeng
 * @name validateonce
 */
 //验证登入
require_once('general/http.php');
include_once( 'general/sso/session_factory.php' );
require_once("general/CGI/ServerEnv.php");
use pateo\general\CGI\ServerEnv;
use pateo\general\sso\session_factory;
 class Validatelogin{
	      public function __construct(){
			  }
	       public  function validate_once($ticket){
			   
			    $host = 'http://login.crm.pateo.com.cn';
			    //地址
			    $validate_url = '/user/ValidateOnce?ticket=%s&cip=%s';
				$cip = ServerEnv::get_ip();
			    $v_url  = sprintf( $validate_url,$ticket,$cip);
				
				$z = $host.$v_url;
				$s =get_url_content( $z );
				$error = json_decode($s,true);
				if($error["Errot_str"] == 'E00000000')
				{
				//存值验证第二次访问login页面
				$crm_session   = session_factory::get_session_instance( 'crm' );
				$crm_session -> set_value( 'uid', $error["uid"] );
				$crm_session -> set_value( 'ticket', $error["ticket"] );
				$crm_session->set_value( 'cti_username', $error[ 'cti_username' ] );
				$crm_session->set_value( 'cti_password', $error[ 'cti_password' ] );
				$crm_session->set_value( 'username', $error['username' ]);
				$crm_session->set_value( 'operator_mail', $error[ 'email']);
				$crm_session->set_value( 'operator_id', $error[ 'uid'] );
				//$crm_session->set_value( 'tel',  $error[ 'tel']  );
					return true;
				}else{
				    return false;
				}
				
			  }  
	/**
	 * CURL发GET请求
	 * 
	 * @param string $url
	 *        	URL地址
	 * @return Result
	 */
 private function getUrl($url) {
		$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_URL, $url );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
		curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 );
		curl_exec ( $ch );
		$result = curl_multi_getcontent ( $ch );
		curl_close ( $ch );
		return $result;
	}
		  public function __destruct(){
		
	          }
	 }
?>
